package com.wlk.service.impl;

import com.wlk.mapper.AdminsMapper;
import com.wlk.pojo.Admins;
import com.wlk.service.AdminsService;
import com.wlk.utils.PhoneNumberValidator;
import com.wlk.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AdminsServiceImpl implements AdminsService {
    @Resource
    private AdminsMapper adminsMapper;

    @Override
    public Result login(String phone, String password) {
        boolean phone_is_ture = PhoneNumberValidator.validate(phone);
        if (!phone_is_ture) {
            return Result.fail("手机号码格式不正确");
        }
        Integer isDisabled = adminsMapper.checkIsDisabled(phone);
        if (isDisabled .equals(1)) {
            return Result.fail("该账号已被禁用");
        } else if (isDisabled.equals(null)) {
            return Result.fail("该账号不存在");
        }
        Admins admin = adminsMapper.getByPhoneAndPassword(phone, password);
        if (admin == null) {
            return Result.fail("手机号或密码错误");
        }
        return Result.ok(admin);
    }
}
